package cl.webservice;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;


public class WebserviceSms {

	private static String METHOD_NAME ;
	private static String NAMESPACE ;
	private static String URL;
    String datosJsonString= "";
	
	public void coneccionwsPropio(){

		METHOD_NAME = "smsandroid";
		NAMESPACE = "http://ws.cl/";
		URL = "http://186.10.182.116:8080/AndroidSmsws/services/MensajesWs";
	}
	
	public void coneccionwsExterno(){

		METHOD_NAME = "smsandroid";
		NAMESPACE = "http://ws.cl/";
		URL = "http://200.13.4.205:8080/AndroidSmsws1/services/MensajesWs?wsdl";
	}
	/**
	 * 
	 * @param methodName
	 */

	public String obtenerSms(){

		coneccionwsPropio();
		
		String SOAP_ACTION = NAMESPACE + METHOD_NAME;
		
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		soapEnvelope.dotNet = true;
		soapEnvelope.implicitTypes =true;
		soapEnvelope.setOutputSoapObject(request);
	
		AndroidHttpTransport aht = new AndroidHttpTransport(URL);
		
		
		try
		{
			aht.call(SOAP_ACTION, soapEnvelope);
			SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
			datosJsonString =resultString.toString();
			return datosJsonString;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			datosJsonString = "Error Conexion";}
			return datosJsonString;
		

	}
}
